<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:visuals="clr-namespace:Eniux.Windows.ThreeDEngine.Visual3Ds"
    xmlns:input="clr-namespace:Eniux.Windows.Input;assembly=Eniux.Windows"
    xmlns:local="clr-namespace:Eniux.Windows.ThreeDEngine.Base"
    xmlns:attach="clr-namespace:Eniux.Windows.ThreeDEngine.AttachObject"
    xmlns:camer="clr-namespace:Eniux.Windows.ThreeDEngine.Base.CameraControllers"
    xmlns:converters="clr-namespace:Eniux.Windows.ThreeDEngine.Base.Converters">
    <converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
    <converters:NotNullToVisibilityConverter x:Key="NotNullToVisibilityConverter"/>
    <Style TargetType="{x:Type local:EniuxViewport3D}">
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:EniuxViewport3D}">
                    <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid FocusVisualStyle="{x:Null}">
                            <camer:CameraController x:Name="PART_CameraController" 
                                attach:AttachCamera.ShowCameraTarget="{Binding ShowCameraTarget,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.CameraRotationMode="{Binding CameraRotationMode,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.CameraMode="{Binding CameraMode,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.ModelUpDirection="{Binding ModelUpDirection,RelativeSource={RelativeSource TemplatedParent}}"
                                attach:AttachCamera.MinimumFieldOfView="{Binding MinimumFieldOfView,RelativeSource={RelativeSource TemplatedParent}}"
                                attach:AttachCamera.MaximumFieldOfView="{Binding MaximumFieldOfView,RelativeSource={RelativeSource TemplatedParent}}"
                                attach:AttachCamera.RotateAroundMouseDownPoint="{Binding RotateAroundMouseDownPoint,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.ZoomAroundMouseDownPoint="{Binding ZoomAroundMouseDownPoint,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.InfiniteSpin="{Binding InfiniteSpin,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.InertiaFactor="{Binding InertiaFactor,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.RotationSensitivity="{Binding RotationSensitivity,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.ZoomSensitivity="{Binding ZoomSensitivity,RelativeSource={RelativeSource TemplatedParent}}" 
                  
                                attach:AttachCamera.PanCursor="{Binding PanCursor,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.RotateCursor="{Binding RotateCursor,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.ZoomCursor="{Binding ZoomCursor,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.ZoomRectangleCursor="{Binding ZoomRectangleCursor,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.ChangeFieldOfViewCursor="{Binding ChangeFieldOfViewCursor,RelativeSource={RelativeSource TemplatedParent}}" 
                                                    
                                attach:AttachCamera.IsPanEnabled="{Binding IsPanEnabled,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.IsZoomEnabled="{Binding IsZoomEnabled,RelativeSource={RelativeSource TemplatedParent}}" 
                                attach:AttachCamera.IsRotationEnabled="{Binding IsRotationEnabled,RelativeSource={RelativeSource TemplatedParent}}" 
                                IsChangeFieldOfViewEnabled="{TemplateBinding IsChangeFieldOfViewEnabled}">
                                <camer:CameraController.InputBindings>
                                    <input:InputBindingX AssociatedGesture="{Binding ResetCameraKeyGesture, RelativeSource={RelativeSource TemplatedParent}}" Command="{x:Static camer:CameraController.ResetCameraCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding RotateGesture, RelativeSource={RelativeSource TemplatedParent}}" Command="{x:Static camer:CameraController.RotateCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding PanGesture, RelativeSource={RelativeSource TemplatedParent}}" Command="{x:Static camer:CameraController.PanCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding ZoomGesture, RelativeSource={RelativeSource TemplatedParent}}" Command="{x:Static camer:CameraController.ZoomCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding ZoomRectangleGesture, RelativeSource={RelativeSource TemplatedParent}}" Command="{x:Static camer:CameraController.ZoomRectangleCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding ChangeFieldOfViewGesture, RelativeSource={RelativeSource TemplatedParent}}" Command="{x:Static camer:CameraController.ChangeFieldOfViewCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding ChangeLookAtGesture, RelativeSource={RelativeSource TemplatedParent}}" Command="{x:Static camer:CameraController.ChangeLookAtCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding ZoomExtentsGesture, RelativeSource={RelativeSource TemplatedParent}}" Command="{x:Static camer:CameraController.ZoomExtentsCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding ResetCameraGesture, RelativeSource={RelativeSource TemplatedParent}}" Command="{x:Static camer:CameraController.ResetCameraCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding TopViewGesture, RelativeSource={RelativeSource TemplatedParent}}"  Command="{x:Static camer:CameraController.TopViewCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding BottomViewGesture, RelativeSource={RelativeSource TemplatedParent}}"  Command="{x:Static camer:CameraController.BottomViewCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding LeftViewGesture, RelativeSource={RelativeSource TemplatedParent}}"  Command="{x:Static camer:CameraController.LeftViewCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding RightViewGesture, RelativeSource={RelativeSource TemplatedParent}}"  Command="{x:Static camer:CameraController.RightViewCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding FrontViewGesture, RelativeSource={RelativeSource TemplatedParent}}"  Command="{x:Static camer:CameraController.FrontViewCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding BackViewGesture, RelativeSource={RelativeSource TemplatedParent}}"  Command="{x:Static camer:CameraController.BackViewCommand}"/>
                                    <input:InputBindingX AssociatedGesture="{Binding OrthographicToggleGesture, RelativeSource={RelativeSource TemplatedParent}}"  Command="{x:Static local:EniuxViewport3D.OrthographicToggleCommand}"/>
                                </camer:CameraController.InputBindings>

                                <AdornerDecorator x:Name="PART_AdornerLayer" DataContext="{TemplateBinding DataContext}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                                    <!-- the main viewport3D is inserted here -->
                                </AdornerDecorator>
                            </camer:CameraController>

                            <!-- Coordinate system -->
                            <Viewport3D x:Name="PART_CoordinateView" Width="80" Height="80" Margin="0" HorizontalAlignment="Left" VerticalAlignment="Bottom" ClipToBounds="False" Visibility="{TemplateBinding ShowCoordinateSystem, Converter={StaticResource BoolToVisibilityConverter}}">
                                <visuals:ArrowVisual3D Point2="10 0 0" Fill="#964B4B" />
                                <visuals:ArrowVisual3D Point2="0 10 0" Fill="#4B964B" />
                                <visuals:ArrowVisual3D Point2="0 0 10" Fill="#4B4B96" />
                                <visuals:PieSliceVisual3D Normal="1,0,0" UpVector="0,0,1" InnerRadius="3" OuterRadius="6"  Fill="#80ff0000"/>
                                <visuals:PieSliceVisual3D Normal="0,1,0" UpVector="1,0,0" InnerRadius="3" OuterRadius="6"  Fill="#8000ff00"/>
                                <visuals:PieSliceVisual3D Normal="0,0,1" UpVector="0,1,0" InnerRadius="3" OuterRadius="6"  Fill="#800000ff"/>

                            </Viewport3D>


                            <Grid IsHitTestVisible="False">
                                <!-- Titles -->
                                <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5" Background="{TemplateBinding TitleBackground}">
                                    <TextBlock Text="{TemplateBinding Title}" 
                                               FontWeight="Bold" FontFamily="{TemplateBinding TitleFontFamily}" FontSize="{TemplateBinding TitleSize}" 
                                               Foreground="{TemplateBinding TextBrush}" 
                                               Visibility="{TemplateBinding Title, Converter={StaticResource NotNullToVisibilityConverter}}"/>
                                    <TextBlock Text="{TemplateBinding SubTitle}" 
                                               FontSize="{TemplateBinding SubTitleSize}" FontFamily="{TemplateBinding TitleFontFamily}" 
                                               Foreground="{TemplateBinding TextBrush}" 
                                               Visibility="{TemplateBinding SubTitle, Converter={StaticResource NotNullToVisibilityConverter}}"/>
                                </StackPanel>

                                <StackPanel HorizontalAlignment="Right" VerticalAlignment="Top" Margin="6" Background="{TemplateBinding InfoBackground}">
                                    <TextBlock HorizontalAlignment="Right" Padding="4" Text="{TemplateBinding FrameRateText}" Foreground="{TemplateBinding TextBrush}" Visibility="{TemplateBinding ShowFrameRate, Converter={StaticResource BoolToVisibilityConverter}}" />
                                    <TextBlock HorizontalAlignment="Right" Padding="4" Text="{TemplateBinding FieldOfViewText}" Foreground="{TemplateBinding TextBrush}" Visibility="{TemplateBinding ShowFieldOfView, Converter={StaticResource BoolToVisibilityConverter}}" />
                                    <TextBlock HorizontalAlignment="Right" Text="{TemplateBinding Status}" Foreground="{TemplateBinding TextBrush}" Visibility="{TemplateBinding Status, Converter={StaticResource NotNullToVisibilityConverter}}"/>
                                </StackPanel>

                                <StackPanel HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="6" Background="{TemplateBinding InfoBackground}">
                                    <TextBlock Text="{TemplateBinding CameraInfo}" Padding="4" Foreground="{TemplateBinding TextBrush}" Visibility="{TemplateBinding ShowCameraInfo, Converter={StaticResource BoolToVisibilityConverter}}" />
                                    <TextBlock Text="{TemplateBinding TriangleCountInfo}" Padding="4" Foreground="{TemplateBinding TextBrush}" Visibility="{TemplateBinding ShowTriangleCountInfo, Converter={StaticResource BoolToVisibilityConverter}}" />
                                    <TextBlock Text="{TemplateBinding DebugInfo}" Visibility="{TemplateBinding DebugInfo, Converter={StaticResource NotNullToVisibilityConverter}}"/>
                                </StackPanel>
                            </Grid>

                            <Viewport3D x:Name="PART_ViewCubeViewport" Width="100" Height="100" Margin="0,20,40,0" Opacity="0.5" HorizontalAlignment="Right" VerticalAlignment="Top" Visibility="{TemplateBinding ShowViewCube, Converter={StaticResource BoolToVisibilityConverter}}">
                                <visuals:ViewCubeVisual3D x:Name="PART_ViewCube" 
                                    ModelUpDirection="{Binding ModelUpDirection, RelativeSource={RelativeSource TemplatedParent}}" 
                                    attach:AttachViewCube.TopText="{Binding TopText,RelativeSource={RelativeSource TemplatedParent}}"
                                    attach:AttachViewCube.BottomText="{Binding BottomText, RelativeSource={RelativeSource TemplatedParent}}"
                                    attach:AttachViewCube.FrontText="{Binding FrontText,RelativeSource={RelativeSource TemplatedParent}}"
                                    attach:AttachViewCube.BackText="{Binding BackText,RelativeSource={RelativeSource TemplatedParent}}"
                                    attach:AttachViewCube.LeftText="{Binding LeftText, RelativeSource={RelativeSource TemplatedParent}}"
                                    attach:AttachViewCube.RightText="{Binding RightText,RelativeSource={RelativeSource TemplatedParent}}"/>
                            </Viewport3D>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
